package ch02Sort;

import edu.princeton.cs.algs4.StdRandom;

public abstract class Sort {
    public static Integer[] a;
    static {
        a = new Integer[50];

        for (int i = 0; i < a.length; i++) {
            a[i] = new Integer(a.length-i);
        }
        StdRandom.shuffle(a);
        System.out.print("原数组：");
        show(a);
    }

    public static boolean less(Comparable a, Comparable b) {
        return a.compareTo(b) < 0;
    }

    public static void exch(Comparable[] a, int i,int j) {
        Comparable t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void show(Comparable[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]+" ");
        }
        System.out.println();
    }

    public static boolean isSorted(Comparable[] a) {
        for (int i = 1; i < a.length; i++) {
            if(less(a[i],a[i-1])) return false;
        }
        return true;
    }

}
